package com.zhilianbao.leyaogo.ui.fragment.me.myorder;

import com.bql.utils.EventManager;
import com.zhilianbao.leyaogo.events.LeEventCode;
import com.zhilianbao.leyaogo.model.response.me.MyOrderResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liu on 2016/10/25.
 * 配送中
 */
public class SendingFragment extends BaseOrderFragment {


    public static SendingFragment getInstance() {
        SendingFragment fragment = new SendingFragment();
        return fragment;
    }

    @Override
    public boolean registerEventBus() {
        return true;
    }

    @Override
    protected void onHandleEvent(EventManager eventManager) {
        super.onHandleEvent(eventManager);
        switch (eventManager.getEventCode()) {
            case LeEventCode.MSG_CODE_SURE_RECEIVE:
                int orderType = (int) eventManager.getData();
                if (mMyOrderAdapter != null && orderType != 3) {
                    loadDataList(1, false);
                }else if (mMyOrderAdapter != null && orderType == 3) {
                    if (mList.size() == 0) {
                        loadDataList(1, false);
                    }
                }
                break;
            case LeEventCode.MSG_CODE_ORDER_DETAIL_SURE_RECEIVE:
                if (mMyOrderAdapter != null) {
                    loadDataList(1,false);
                }
                break;
        }

    }

    @Override
    public int getType() {
        //配送中返回3
        return 3;
    }

    @Override
    public void initCurrentChild() {
        //0 all,1 waitToPay,2 waitToSend,3 sending,4 finish
        currentChild = 3;
    }

//    @Override
//    public String getEmptyContent() {
//        return "主人,您的待收货订单为空";
//    }
    @Override
    public List<MyOrderResponse> getList(List<MyOrderResponse> myOrderResponses) {
        ArrayList<MyOrderResponse> list = new ArrayList<>();
        if (myOrderResponses==null)
            return null;
        for (int i = 0; i < myOrderResponses.size(); i++) {
            MyOrderResponse myOrderResponse = myOrderResponses.get(i);
            int orderCode = myOrderResponse.getOrderCode();
            if (orderCode == 5 ) {
                list.add(myOrderResponse);
            }
        }
        return list;
    }
}
